package com.fwj.auth.strategy;

import com.fwj.auth.entity.user.UserExtendAccount;
import com.fwj.auth.model.BindInfo;
import com.fwj.auth.strategy.impl.BindInfoStrategyImpl;

/**
 * @Author: fwj
 * @Data: 2022/4/23 18:54
 * @Version 1.0
 * @Description:
 */


public enum BingInfoStrategy {
    // 绑定信息策略枚举
    /**
     * 手机
     */
    PHONE("Phone", BindInfoStrategyImpl.PHONE),
    /**
     * 邮箱
     */
    EMAIL("Email", BindInfoStrategyImpl.EMAIL),
    /**
     * 微信
     */
    WECHAT("Wechat", BindInfoStrategyImpl.WECHAT),
    /**
     * QQ
     */
    QQ("QQ", BindInfoStrategyImpl.QQ),
    /**
     * 微博
     */
    MICRO_BLOG("MicroBlog", BindInfoStrategyImpl.MICRO_BLOG),
    ;

    private final String strategy;

    private final BindInfoStrategyImpl bindInfoStrategy;

    //获取策略
    public String getStrategy() {
        return strategy;
    }

    BingInfoStrategy(String strategy, BindInfoStrategyImpl bindInfoStrategy) {
        this.strategy = strategy;
        this.bindInfoStrategy = bindInfoStrategy;
    }

    //策略执行
    public void execStrategy(BindInfo bindInfo,UserExtendAccount userExtendAccount) throws Exception {
        bindInfoStrategy.exec(bindInfo,userExtendAccount);
    }

    //匹配策略，可优化
    public static BingInfoStrategy matchStrategy(String strategy) {
        for (BingInfoStrategy bingInfoStrategy : BingInfoStrategy.values()) {
            //返回匹配成功的策略
            if (bingInfoStrategy.getStrategy().equals(strategy)) {
                return bingInfoStrategy;
            }
        }
        return null;
    }
}
